package ua.kpi.flats.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import ua.kpi.flats.dao.UserDao;
import ua.kpi.flats.entity.User;
import ua.kpi.flats.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {
	private Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
	
	private UserDao userDao;
	
	@Transactional(readOnly = true,
			       propagation = Propagation.REQUIRES_NEW,
			       isolation = Isolation.READ_COMMITTED)
	public User getUser(String userName) {
		try {
			return userDao.getUser(userName);
		} catch (DataAccessException e) {
			logger.error("Cant get user identified by " + userName,e);
			return null;
		}		
	}
	
	@Autowired	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
}
